import vue from '@vitejs/plugin-vue'

import Unocss from 'unocss/vite'
import { lazyImport, VxeResolver } from 'vite-plugin-lazy-import'
import vueDevTools from 'vite-plugin-vue-devtools'
import createAutoImport from './auto-import'
import createComponents from './components'
import createCompression from './compression'
import createSetupExtend from './setup-extend'
import createSvgIcon from './svg-icon'

export default function createVitePlugins(viteEnv, isBuild = false) {
  const vitePlugins = [vue()]
  vitePlugins.push(createAutoImport())
  vitePlugins.push(createSetupExtend())
  vitePlugins.push(createSvgIcon(isBuild))
  vitePlugins.push(createComponents())
  vitePlugins.push(
    lazyImport({
      resolvers: [
        VxeResolver({
          libraryName: 'vxe-table',
        }),
        VxeResolver({
          libraryName: 'vxe-pc-ui',
        }),
      ],
    }),
  )
  vitePlugins.push(
    vueDevTools(),
  )
  vitePlugins.push(Unocss())
  isBuild && vitePlugins.push(...createCompression(viteEnv))
  return vitePlugins
}
